package com.yanqu.road.server.cmd.activity.seacraftsouthsea;

import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.logic.helper.RandomWeightConfigHelper;
import com.yanqu.road.pb.activity.SeacraftSouthSeaProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.seacraft.SeacraftSouthSeaModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.manger.SeacraftSouthSeaCommonMgr;
import com.yanqu.road.server.manger.activity.seacraft.SeacraftSouthSeaMgr;
import com.yanqu.road.server.manger.system.CommonMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.math.BigInteger;

/**
 * @Description
 * @Author cwq
 * @Data 2022/1/20 15:28
 */
@Cmd(code = GameProtocol.S_SEACRAFT_SOUTH_SEA_DONATION_SHIP_FROM_CROSS, desc = "海上争霸 南海丝路 捐献 跨服返回区服 协议")
public class SeacraftSouthSeaDonationShipFromCrossCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        SeacraftSouthSeaProto.SeacraftSouthSeaDonationShipCrossToGameMsg crossToGameMsg = SeacraftSouthSeaProto.SeacraftSouthSeaDonationShipCrossToGameMsg.parseFrom(packet.getBytes());
        // 取消预扣除
        Property consume = PropertyHelper.parseStringToProperty(crossToGameMsg.getConsume());
        player.getModule(PreReduceModule.class).restorePreReduce(consume);
        if (crossToGameMsg.getStcMsg().getRet() == 0) {
            // 扣道具
            player.getModule(CurrencyModule.class).removeCurrency(consume,eLogMoneyType.SeacraftActivity, eLogMoneyType.SeacraftActivityDonationShipCost);
            // 加捐献奖励
            Property reward = PropertyHelper.parseStringToProperty(crossToGameMsg.getStcMsg().getReward());
            player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.SeacraftActivity, eLogMoneyType.SeacraftActivityDonationShipReward);
        }
        player.sendPacket(ClientProtocol.U_SEACRAFT_SOUTH_SEA_DONATION_SHIP, crossToGameMsg.getStcMsg().toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
